import json
import os
import sys
from record_log import record_log
from fastapi import FastAPI, BackgroundTasks
from fastapi.responses import JSONResponse

app = FastAPI()
# 将脚本所在目录添加到 sys.path
os.chdir(os.path.abspath(os.path.dirname(__file__)))

try:
    from clean_report_data import get_daily_report, query_tops_questions
    from write_back_tb import write_back_tb
except ImportError as e:
    print(f"Error importing modules: {e}")
    sys.exit(1)


def main():
    # 清洗数据库数据
    flag = get_daily_report()
    if flag:
        query_tops_questions()
        # 写回数据
        # write_back_tb()
    else:
        print('近一天没有新增的top3问题')
        record_log('近一天没有新增的top3问题',"info")


        
        
    


if __name__ == '__main__':
    main()
    # 设置定时运行
    # crontab -e
    # 添加定时任务
    # 30 12 * * * /home/xc/zy/sales_top3_project/venv/bin/python3  /home/xc/zy/sales_top3_project/top3_sales_processing/codes/run.py >> /home/xc/zy/sales_top3_project/log/run.log 2>&1
    
    # 查看已添加的定时任务
    
    # crontab -l


    

